<template>
  <el-dialog v-loading="loading" :append-to-body="true" :close-on-click-modal="false" :visible.sync="visable" title="新增流程" width="400px" @close="closeDlg">
    <el-form ref="xform" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="流程ID" prop="key">
        <el-input v-model="form.key" maxlength="30" style="width:200px;" />
        <el-tooltip class="item" effect="light" content="新建后，流程标识不可修改！" placement="top">
          <i style="padding-left: 5px;" class="el-icon-question" />
        </el-tooltip>
      </el-form-item>
      <el-form-item label="流程名称" prop="name">
        <el-input v-model="form.name" maxlength="40" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ProcessDefVOForm',
  data() {
    return {
      isAdd: false,
      loading: false,
      visable: false,
      form: {
        name: '',
        key: ''
      },
      rules: {
        key: [
          { required: true, message: '请输入流程ID', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入流程名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    resetFields() {
      this.$refs['xform'].resetFields()
      this.form = {
        name: '',
        key: ''
      }
    },
    cancel() {
      this.closeDlg()
    },
    add() {
      this.isAdd = true
      this.visable = true
    },
    doSubmit() {
      this.$refs['xform'].validate((valid) => {
        if (valid) {
          this.$router.push({ path: '/sys/processdesign?key=' + encodeURIComponent(this.form.key) + '&name=' + encodeURIComponent(this.form.name) })
          this.closeDlg()
        }
      })
    },
    closeDlg() {
      this.visable = false
      this.resetFields()
    }
  }
}
</script>
